1 using System;
2 using
System.Collections.Generic;
3 using
System.IO;
4 using
UnityEngine;
5 using
UnityEditor;
6
7 [InitializeOnLoad]

8 public
class PunStartup : MonoBehaviour
9 {
10     
// paths to demo scenes to setup (if needed)
11     
private const string demoBasePath = "Assets/Photon Unity Networking/Demos/";
12     
private static string[] demoPaths =
13         {
14             
"DemoHub/DemoHub-Scene.unity",
15             
"DemoBoxes/DemoBoxes-Scene.unity",
16             
"DemoWorker/DemoWorker-Scene.unity",
17             
"DemoWorker/DemoWorkerGame-Scene.unity",
18             
"MarcoPolo-Tutorial/MarcoPolo-Scene.unity",
19             
"DemoSynchronization/DemoSynchronization-Scene.unity",
20             
"DemoFriendsAndCustomAuth/DemoFriends-Scene.unity",
21             
"DemoFriendsAndCustomAuth/DemoPickup-Scene.unity",
22             
"DemoChat/DemoChat-Scene.unity"
23         };
24
25     
static PunStartup()
26     {
27         
bool doneBefore = EditorPrefs.GetBool("PunDemosOpenedBefore");
28         
if (!doneBefore)
29         {
30             EditorApplication.update += OnUpdate;
31         }
32     }
33
34     
static void OnUpdate()
35     {
36         
bool doneBefore = EditorPrefs.GetBool("PunDemosOpenedBefore");
37         
if (doneBefore)
38         {
39             EditorApplication.update -= OnUpdate;
40             
return;
41         }
42
43         
if (String.IsNullOrEmpty(EditorApplication.currentScene) && EditorBuildSettings.scenes.Length == 0)
44         {
45             #
if UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5 || UNITY_5_1 || UNITY_5_2
46             
if (EditorApplication.isUpdating) return;
47             #endif
48
49             LoadPunDemoHub();
50             SetPunDemoBuildSettings();
51             EditorPrefs.SetBool(
"PunDemosOpenedBefore", true);
52             Debug.Log(
"No scene was open. Loaded PUN Demo Hub Scene and added demos to build settings. Ready to go! This auto-setup is now disabled in this Editor.");
53         }
54     }
55
56     
[MenuItem("Window/Photon Unity Networking/Apply Build Setup for Demos")]
57     
public static void SetupDemo()
58     {
59         SetPunDemoBuildSettings();
60     }
61
62     
//[MenuItem("Window/Photon Unity Networking/PUN Demo Loader Reset")]
63     
//protected static void ResetDemoLoader()
64     
//{
65     
// EditorPrefs.DeleteKey("PunDemosOpenedBefore");
66     
//}
67
68     
public static void LoadPunDemoHub()
69     {
70         
bool ret = EditorApplication.OpenScene(demoBasePath + demoPaths[0]);
71         
if (ret)
72         {
73             Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(demoBasePath + demoPaths[
0]);
74         }
75     }

76
77     ///
<summary>
78     ///
Finds scenes in "Assets/Photon Unity Networking/Demos/", excludes those in folder "PUNGuide_M2H" and applies remaining scenes to build settings. The one with "Hub" in it first.
79     ///
</summary>
80     
public static void SetPunDemoBuildSettings()
81     {
82         
// find path of pun guide
83         
string[] tempPaths = Directory.GetDirectories(Application.dataPath + "/Photon Unity Networking", "Demos", SearchOption.AllDirectories);
84         
if (tempPaths == null || tempPaths.Length != 1)
85         {
86             
return;
87         }
88
89         
// find scenes of guide
90         
string guidePath = tempPaths[0];
91         tempPaths = Directory.GetFiles(guidePath,
"*.unity", SearchOption.AllDirectories);
92
93         
if (tempPaths == null || tempPaths.Length == 0)
94         {
95             
return;
96         }
97
98         
// add found guide scenes to build settings
99         List<EditorBuildSettingsScene> sceneAr =
new List<EditorBuildSettingsScene>();
100         
for (int i = 0; i < tempPaths.Length; i++)
101         {
102             
//Debug.Log(tempPaths[i]);
103             
string path = tempPaths[i].Substring(Application.dataPath.Length - "Assets".Length);
104             path = path.Replace(
'\\', '/');
105             
//Debug.Log(path);
106
107             
if (path.Contains("PUNGuide_M2H"))
108             {
109                 
continue;
110             }
111
112             
if (path.Contains("Hub"))
113             {
114                 sceneAr.Insert(
0, new EditorBuildSettingsScene(path, true));
115                 
continue;
116             }
117
118             sceneAr.Add(
new EditorBuildSettingsScene(path, true));
119         }
120
121         EditorBuildSettings.scenes = sceneAr.ToArray();
122         EditorApplication.OpenScene(sceneAr[
0].path);
123     }
124 }


paths to demo scenes to setup (if needed)

[MenuItem("WindowPhoton Unity NetworkingPUN Demo Loader Reset")]

protected static void ResetDemoLoader()

{

EditorPrefs.DeleteKey("PunDemosOpenedBefore");

}

Finds scenes in "AssetsPhoton Unity NetworkingDemos", excludes those in folder "PUNGuide_M2H" and applies remaining scenes to build settings. The one with "Hub" in it first.

find path of pun guide

find scenes of guide

add found guide scenes to build settings

Debug.Log(tempPaths[i]);

Debug.Log(path);




Trò chơi Tic-Tac-Toe, game đánh caro full source code 53.476 lượt xem

Gõ tìm kiếm nhanh...